Completed
Push — master ( 2281e8...8b163e )
by Justin
01:35
created

uctor does not copy instancesꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 9.4285
1
var assert = require('chai').assert,
2
    GedcomX = require('../');
3
4
describe('Note', function(){
5
  
6
  it('Create plain', function(){
7
    var newNote = new GedcomX.Note(),
8
        note = GedcomX.Note();
9
    assert.instanceOf(newNote, GedcomX.Note, 'An instance of Note is not returned when calling the constructor with new.');
10
    assert.instanceOf(note, GedcomX.Note, 'An instance of Note is not returned when calling the constructor without new.');
11
  });
12
  
13
  it('Create with JSON', function(){
14
    var note = GedcomX.Note({
15
      id: 'note',
16
      lang: 'en',
17
      subject: 'A subject',
18
      text: 'Lots of text',
19
      attribution: {
20
        changeMessage: 'It changed',
21
        contributor: { resource: 'https://myapp.com/contributor'}
22
      }
23
    });
24
    assert.equal(note.getId(), 'note');
25
    assert.equal(note.getLang(), 'en');
26
    assert.equal(note.getSubject(), 'A subject');
27
    assert.equal(note.getText(), 'Lots of text');
28
    assert.equal(note.getAttribution().getContributor().getResource(), 'https://myapp.com/contributor');
29
  });
30
  
31
  it('Create with mixed data', function(){
32
    var note = GedcomX.Note({
33
      id: 'note',
34
      lang: 'en',
35
      subject: 'A subject',
36
      text: 'Lots of text',
37
      attribution: new GedcomX.Attribution({
38
        changeMessage: 'It changed',
39
        contributor: { resource: 'https://myapp.com/contributor'}
40
      })
41
    });
42
    assert.equal(note.getId(), 'note');
43
    assert.equal(note.getLang(), 'en');
44
    assert.equal(note.getSubject(), 'A subject');
45
    assert.equal(note.getText(), 'Lots of text');
46
    assert.equal(note.getAttribution().getContributor().getResource(), 'https://myapp.com/contributor');
47
  });
48
  
49
  it('Build', function(){
50
    var note = GedcomX.Note()
51
      .setId('note')
52
      .setLang('en')
53
      .setSubject('A subject')
54
      .setText('Lots of text')
55
      .setAttribution({
56
        changeMessage: 'It changed',
57
        contributor: { resource: 'https://myapp.com/contributor'}
58
      });
59
    assert.equal(note.getId(), 'note');
60
    assert.equal(note.getLang(), 'en');
61
    assert.equal(note.getSubject(), 'A subject');
62
    assert.equal(note.getText(), 'Lots of text');
63
    assert.equal(note.getAttribution().getContributor().getResource(), 'https://myapp.com/contributor');
64
  });
65
  
66
  it('toJSON', function(){
67
    var noteData = {
68
        id: 'note',
69
        lang: 'en',
70
        subject: 'A subject',
71
        text: 'Lots of text',
72
        attribution: {
73
          changeMessage: 'It changed',
74
          contributor: { resource: 'https://myapp.com/contributor'}
75
        }
76
      },
77
      note = GedcomX.Note(noteData);
78
    assert.deepEqual(note.toJSON(), noteData);
79
  });
80
  
81
  it('constructor does not copy instances', function(){
82
    var obj1 = GedcomX.Note();
83
    var obj2 = GedcomX.Note(obj1);
84
    assert.strictEqual(obj1, obj2);
85
  });
86
  
87
});